﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace UserNotificationAspMvc.Models
{
    public enum NotificationType
    {
        Error = 1,
        Success = 2,
        Info = 3
    }

    public enum BarAnimationDirection
    {
        right,
        left
    }

    public class UserNotification
    {
        public Guid NotificationId { get; set; }
        public string Message { get; private set; }
        public string Scream { get; private set; }
        public string Type { get; private set; }
        public ushort Duration { get; private set; }
        public ushort Width { get; private set; }
        public BarAnimationDirection AnimationBarDirection { get; private set; }
        public bool IsAttached { get; set; }

        public UserNotification(string msg, NotificationType msgType = NotificationType.Info, ushort autoClose = 2200, ushort width = 300, BarAnimationDirection barDirection = BarAnimationDirection.right)
        {
            NotificationId = Guid.NewGuid();
            Message = msg;
            Duration = autoClose;
            switch (msgType)
            {
                case NotificationType.Error:
                    Scream = "Oh snap! ";
                    Type = NotificationType.Error.ToString().ToLower();
                    break;
                case NotificationType.Info:
                    Scream = "Heads up!";
                    Type = NotificationType.Info.ToString().ToLower();
                    break;
                case NotificationType.Success:
                    Scream = "Well done!";
                    Type = NotificationType.Success.ToString().ToLower();
                    break;
            }
            Width = width;
            AnimationBarDirection = barDirection;
            IsAttached = false;
        }

        public override string ToString()
        {
            return String.Format(@" MVCNotificationQueue.Add(new MVCNotification('{0}','{1}',{2},'{3}','{4}',{5},'{6}',{7})); ",
                                   this.NotificationId,
                                   this.Type.ToString().ToLower(),
                                   this.Duration,
                                   this.Message.Replace("'", "\'"),
                                   this.Scream,
                                   this.Width,
                                   this.AnimationBarDirection,
                                   this.IsAttached.ToString().ToLower()
                                   );
        }

    }
}